package com.alifi.crm.dal.guess;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.alifi.crm.dal.IbatisCRUDDAO;
import com.alifi.crm.dal.enu.States;
import com.alifi.crm.dal.enu.YesOrNo;
import com.alifi.crm.dal.object.EmployeeGuessDO;



@Repository("employeeGuessDAO")
public class EmployeeGuessDAOImpl extends IbatisCRUDDAO<EmployeeGuessDO> implements EmployeeGuessDAO{

	@Override
	protected String getNamespace() {
		return "act_employee_guess";
	}
	
	@Override
	public EmployeeGuessDO selectByEmployeeNum(String employeeNum) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("employeeNum", employeeNum);
		return (EmployeeGuessDO)this.getSqlMapClientTemplate().queryForObject(this.genStmt("selectByEmployeeNum"),map);
	}

	@Override
	public void updateLimitGuessTimes(Long limitGuessTimes, String employeeNum,Long initTransmitTimes,Long actTransmitTimes) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("limitGuessTimes", limitGuessTimes);
		map.put("employeeNum", employeeNum);
		map.put("initTransmitTimes", initTransmitTimes);
		map.put("actTransmitTimes", actTransmitTimes);
		this.getSqlMapClientTemplate().update(this.genStmt("updateLimitGuessTimes"),map);
	}

	@Override
	public void updateGuessTimes(Long guessTimes, String employeeNum,YesOrNo isRight,States states,String remark) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("guessTimes", guessTimes);
		map.put("employeeNum", employeeNum);
		map.put("states", states.code());
		map.put("isRight", isRight.code());
		map.put("remark", remark);
		this.getSqlMapClientTemplate().update(this.genStmt("updateGuessTimes"),map);		
	}
	
	public int getLockByEmployeeNum(String employeeNum){
		Map<String,String> map = new HashMap<String,String>();
		map.put("employeeNum", employeeNum);
		return this.getSqlMapClientTemplate().update(this.genStmt("getLockByEmployeeNum"),map);
	}
	
	public int releaseLockByEmployeeNum(String employeeNum){
		Map<String,String> map = new HashMap<String,String>();
		map.put("employeeNum", employeeNum);
		return this.getSqlMapClientTemplate().update(this.genStmt("releaseLockByEmployeeNum"),map);
	}

	@Override
	public EmployeeGuessDO selectByIdForUpdate(Long id) {
		return (EmployeeGuessDO)this.getSqlMapClientTemplate().queryForObject(this.genStmt("selectByIdForUpdate"),id);
	}

	@Override
	public int releaseLockTimeOut() {
		return this.getSqlMapClientTemplate().update(this.genStmt("releaseLockTimeOut"));
	}

	@Override
	public void updateStates(States states, String employeeNum) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("states", states.code());
		map.put("employeeNum", employeeNum);
		this.getSqlMapClientTemplate().update(this.genStmt("updateStates"),map);
		
	}
}
